package com.joyintech.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Configuration
public class AsyncTaskPoolConfig {

    // 会和定时任务线程池名称冲突
    @Bean("asyncTaskExecutor")
    @Primary
    public ThreadPoolExecutor asyncTaskExecutor() {
        int i = Runtime.getRuntime().availableProcessors();
        System.out.println("系统最大线程数：" + 5);
        ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(5,
                20, 5, TimeUnit.SECONDS, new LinkedBlockingDeque<>(2000), new NamedThreadFactory("async"));
        System.out.println("异步线程池初始化完毕-------------");
        return threadPoolExecutor;
    }


}
